package com.situ.mall.order.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.order.pojo.vo.CartVO;
import com.situ.mall.order.service.ICartService;
import com.situ.mall.pojo.entity.order.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author Gao
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/order/cart")
public class CartController {
    @Autowired
    private ICartService cartService;

    @GetMapping("/selectByUserId/{id}")
    public Result<List<CartVO>> selectByUserId(@PathVariable Long id) {
        List<CartVO> list = cartService.selectByUserId(id);
        return Result.ok(list);
    }


    @PostMapping("/add")
    public Result<CartVO> add(@RequestBody Cart cart) {
        CartVO cartVO = cartService.add(cart);
        return Result.ok("添加成功", cartVO);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Cart cart) {
        cartService.updateById(cart);
        return Result.ok("更新成功");
    }

}

